package com.campus.web.control;

import com.campus.model.Student;
import com.campus.service.StudentService;
import com.campus.web.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping()
    public ResponseResult<String> addStudent(@RequestBody @Validated Student student) {
        log.info("Adding student: {}", student);
        int result = studentService.addStudent(student);
        if (result > 0) {
            return ResponseResult.ok("学生添加成功");
        } else {
            return ResponseResult.error(HttpStatus.BAD_REQUEST,"添加失败");
        }
    }


    @GetMapping("/check")
    public ResponseResult<String> checkStudentById(
            @RequestParam @NotBlank String comment,
            @RequestParam @NotBlank int id) {
        log.info("Checking student with ID: {}, Comment: {}", id, comment);
        int result = studentService.checkStudentById(comment, id);
        if (result > 0) {
            return ResponseResult.ok("审核通过");
        } else {
            return ResponseResult.error(HttpStatus.BAD_REQUEST,"学生不存在");
        }
    }

}
